package org.hypnus.e.action;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hypnus.e.util.ByteUtil;

public class EServlet extends HttpServlet {
	
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		super.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		req.setCharacterEncoding("utf-8") ;
		Enumeration<String> eStr = req.getHeaderNames() ;
		while(eStr.hasMoreElements()){
			System.out.println(req.getHeader(eStr.nextElement()));
		}
//		System.out.println(req.getParameter("eaContext")) ;
		InputStream is = req.getInputStream() ;
		byte[] arrByte = new byte[1024] ;
		byte[] result = null ;
		while(true){
			int length = is.read(arrByte) ;
			if(length==-1){
				break ;
			}
			result = ByteUtil.join(result, result==null?0:result.length, arrByte, length) ;
		}
//		Gson gson = new Gson() ;
//		EDataset dst = gson.fromJson(new String(result), EDataset.class) ;
//		System.out.println();
		System.out.println(new String(result,"utf-8"));
	}
	
	

}
